<template>
	<view class="list-view">
		<view class="top-bar"><uni-navbar :fixed="true" :back="true" color="#fff" title="我的日程"></uni-navbar></view>

		<view class="list-box" :style="{ background: loading == 'nodata' ? 'none' : '#fff' }">
			<view class="list-info_03" v-for="(item, index) of infoList" :key="item.id" @click="navTo(item)">
				<view class="info-title clamp" v-html="item.content"></view>
				<view class="info-btm">
					<view class="left-time">时间：{{ item.dayDate | parseTime('{y}-{m}-{d}') }}</view>
					<view class="del"><u-button class="form-btn" type="error" size="mini" @click="del(item)">删除</u-button></view>
				</view>
			</view>
			<u-loadmore :status="loading" />
		</view>

		<view class="uploader-add" @click="addTo()"><u-icon name="plus" color="#fff" size="40"></u-icon></view>

		<u-back-top :scroll-top="scrollTop" top="200"></u-back-top>

		<view v-if="false && vacate"></view>
	</view>
</template>

<script>
import { mapState } from 'vuex';
export default {
	data() {
		return {
			scrollTop: 0,
			colorMap: {
				0: '#303133',
				1: '#ff3333',
				2: '#0099ff',
				3: '#ff9900',
				4: '#19be6b'
			},
			statusMap: {
				0: '删除',
				1: '代办',
				2: '已办'
			},
			type: 0,

			infoList: [],

			vacate: {
				status: '',
				type: '0',
				clientCode: ''
			},
			loading: 'loadmore'
		};
	},
	onLoad(option) {
		this.loadLogin();
		this.loadData();
	},
	onShow() {
		this.loadData('refresh');
	},
	onPullDownRefresh() {
		this.loadData('refresh');
	},
	onReachBottom() {
		if (this.loading == 'loadmore') this.loadData('add');
	},
	onPageScroll(res) {
		this.scrollTop = res.scrollTop;
	},
	computed: {
		...mapState(['userInfo'])
	},
	methods: {
		loadLogin() {
			if (this.userInfo.Authorization) {
				this.clientCode = this.userInfo.sysUser.clientCode;
				this.vacate.userId = this.userInfo.sysUser.id;
				this.vacate.clientCode = this.userInfo.sysUser.clientCode;

				this.pageNum = 1;
				this.pageSize = 10;
			} else {
				this.$logout();
			}
		},
		loadData(type = 'add') {
			if (this.loading == 'loading') {
				return false;
			}
			if (type == 'add') {
				if (this.loading == 'nomore') {
					return false;
				}
				this.loading = 'loading';
			} else {
				this.loading = 'loading';
			}
			if (type != 'add') {
				this.pageNum = 1;
			}
			if (this.vacate.type == '0') {
				this.vacate.type = '';
			}
			let data = {
				pageNum: this.pageNum,
				pageSize: this.pageSize,
				oaAttndScheduled: this.vacate
			};
			this.$request('/oaAttndScheduled/oa-attnd-scheduled/list', data, {
				load: true
			}).then((res) => {
				let count = 0;
				if (type != 'add') {
					uni.stopPullDownRefresh();
					this.infoList = [];
				}
				this.loading = this.pageNum < Math.ceil(res.data.total / this.pageSize) ? 'loadmore' : 'nomore';
				this.pageNum = this.pageNum + 1;
				this.infoList = this.infoList.concat(res.data.records);
				this.loaded = true;
				if (this.infoList.length <= 0) {
					this.loading = 'nodata';
				}
			});
		},
		loadDict(type, list) {
			this.$request('/system/sys-dict/dictList', {
				clientCode: this.clientCode,
				sysDict: {
					dictType: type
				}
			}).then((res) => {
				if (!res.data) {
					return false;
				}
				this[list] = [];
				res.data.forEach((item) => {
					this[list].push({
						value: item.dictValue,
						name: item.dictName
					});
				});
			});
		},
		tabsChange(index) {
			this.tabsCurrent = index;
			this.change(this.tabsList[index].value);
		},
		change(e) {
			this.type = e;
			this.vacate.type = e.toString();
			this.loadData('refresh');
		},
		del(item) {
			this.$request(
				'/oaAttndScheduled/oa-attnd-scheduled/del',
				{
					ids: [item.id]
				},
				{
					load: true
				}
			).then((res) => {
				this.$msg(res.msg);
				setTimeout(() => {
					this.loadData('refresh');
				}, 500);
			});
		},
		navTo(item) {
			uni.navigateTo({
				url: '/pagesB/oa/add_no4?id=' + item.id
			});
		},
		addTo() {
			uni.navigateTo({
				url: '/pagesB/oa/add_no4'
			});
		}
	}
};
</script>

<style lang="scss">
.uTabs {
	min-height: 88rpx;
}

.list-box {
	padding: 0 30rpx;
	background-color: #fff;
}

.list-info_03 {
	padding-left: 30rpx;
}

.tianbao {
	display: block;
	position: fixed;
	right: 30rpx;
	bottom: 170rpx;
	width: 160rpx;
	height: 160rpx;
}

.filter-box {
	position: fixed;
	left: 0;
	top: 0;
	bottom: 0;
	right: 0;
	z-index: 998;
	background-color: #fff;
}

.form-box {
	.form-item {
		@include mp-flex;
	}
}

.fiexd-btm {
	position: static;
	padding: 30rpx;
}

.list-box {
	padding: 20rpx 30rpx;
}
</style>
